﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace GolfLeague.Models
{
    public class CourseInterface
    {
        GolfLeagueEntities golfDB = new GolfLeagueEntities();

        public IQueryable<Course> GetAllCourses()
        {
            return from courseEntity in golfDB.Courses
                   orderby courseEntity.CourseName
                   select courseEntity;
        }

        public Course GetCourse(int CourseID)
        {
            var courseQuery = from courseEntity in golfDB.Courses
                              where courseEntity.CourseID.Equals(CourseID)
                              select courseEntity;

            return courseQuery.FirstOrDefault();
        }

        public void AddCourse(Course newCourse)
        {
            golfDB.Courses.AddObject(newCourse);
        }

        public void DeleteCourse(Course course)
        {
            golfDB.Courses.DeleteObject(course);
        }

        public void Save()
        {
            golfDB.SaveChanges();
        }
    }
}